/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.rafkind.resrev.web.page;

import com.rafkind.resrev.dao.ResourceDao;
import com.rafkind.resrev.data.Reservation;
import com.rafkind.resrev.web.Authorized;
import com.rafkind.resrev.web.Session;
import com.rafkind.resrev.web.page.component.CalendarPanel;
import com.rafkind.resrev.web.page.component.MakeReservationPanel;
import com.rafkind.resrev.web.page.component.TitleMenu;
import org.apache.wicket.Page;
import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.spring.injection.annot.SpringBean;

/**
 *
 * @author dave
 */
@Authorized
public class CalendarPage extends WebPage {
  
  @SpringBean
  private ResourceDao resourceDao;
  
  private Page previousPage;
  
  public CalendarPage() {
    add(new TitleMenu("titleMenu"));
    
    if (resourceDao.countAllResources() > 0) {
      add(
        new MakeReservationPanel(
          "makeReservation", 
          new Model(
            new Reservation(
              ((Session)getSession()).getCurrentUser())), null));
    } else {
      add(createNoResourcesLabel());
    }
    add(new CalendarPanel("calendar"));    
  }

  public CalendarPage(IModel<Reservation> model) {
    super(model);
    add(new TitleMenu("titleMenu"));
    if (resourceDao.countAllResources() > 0) {
      add(new MakeReservationPanel("makeReservation", model, null));
    } else {
      add(createNoResourcesLabel());
    }
    add(new CalendarPanel("calendar"));
  }
  
  public CalendarPage(IModel<Reservation> model, Page previousPage) {
    super(model);
    this.previousPage = previousPage;
    
    add(new TitleMenu("titleMenu"));
    if (resourceDao.countAllResources() > 0) {
      add(new MakeReservationPanel("makeReservation", model, previousPage));
    } else {
      add(createNoResourcesLabel());
    }
    add(new CalendarPanel("calendar"));
  }
  
  private Label createNoResourcesLabel() {
    Label label = new Label("makeReservation", "No resources to reserve!");
    
    label.add(
            new SimpleAttributeModifier(
              "style", 
              "font-weight: bold; font-size: 200%; text-align: center"));
    return label;
  }
}
